home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / MacPerl 506 appl folder.sit / MacPerl 506 appl folder / Mac_Perl_506r1m_appl / lib / Carp.pm < prev    next >
Text File  |  1995-03-03  |  1KB  |  47 lines

  1. package Carp;
  2.  
  3. # This package implements handy routines for modules that wish to throw
  4. # exceptions outside of the current package.
  5.  
  6. require Exporter;
  7. @ISA = Exporter;
  8. @EXPORT = qw(confess croak carp);
  9.  
  10. sub longmess {
  11.     my $error = shift;
  12.     my $mess = "";
  13.     my $i = 2;
  14.     my ($pack,$file,$line,$sub);
  15.     while (($pack,$file,$line,$sub) = caller($i++)) {
  16. #    $mess .= "¥t$sub " if $error eq "called";
  17. #    $mess .= "$error at $file line $line¥n";
  18. #    $error = "called";
  19.     if ($error eq "called") {
  20.         $mess .= "#¥t$sub called¥n";
  21.     } else {
  22.         $mess .= "# $error¥n";
  23.     }
  24.     $mess .= "File ¥'$file¥'; Line $line¥n";
  25.     $error = "called";
  26.     }
  27. #    $mess || $error;
  28.     $mess || "# $error";
  29. }
  30.  
  31. sub shortmess {
  32.     my $error = shift;
  33.     my ($curpack) = caller(1);
  34.     my $i = 2;
  35.     my ($pack,$file,$line,$sub);
  36.     while (($pack,$file,$line,$sub) = caller($i++)) {
  37. #    return "$error at $file line $line¥n" if $pack ne $curpack;
  38.     return "# $error¥nFile ¥'$file¥'; Line $line¥n" if $pack ne $curpack;
  39.     }
  40.     longmess $error;
  41. }
  42.  
  43. sub confess { die longmess @_; }
  44. sub croak { die shortmess @_; }
  45. sub carp { warn shortmess @_; }
  46.  
  47.